package com.cch.examSystem.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.cch.examSystem.entity.Manager;
import com.cch.examSystem.entity.StudentList;

public class StudentListServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		Date now = new Date();
		SimpleDateFormat datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();

		List userList = new ArrayList();
		StudentList user;
		String name = "测试学生";
		String identity = "44150019998888000";
		for (int i = 0; i < 15; i++) {
			user = new StudentList(i, name + i, identity + i, "123456", "本科",
					"软件工程", "1562603045" + i, date.format(now),
					datetime.format(now), "192.168.1." + i, "96502715" + i
							+ "@qq.com");
			user.setSex("男");
			userList.add(user);
		}
		for (int i = 15; i < 30; i++) {
			user = new StudentList(i, name + i, identity + i, "123456", "专科",
					"网络工程", "1562603045" + i, date.format(now),
					datetime.format(now), "192.168.1." + i, "96502715" + i
							+ "@qq.com");
			user.setSex("女");
			userList.add(user);
		}
		/* System.out.println(JSON.toJSONString(userList)); */
		request.setAttribute("userList", userList);
		request.getRequestDispatcher("./manager/studentList.jsp").forward(
				request, response);
		out.flush();
		out.close();
	}

}
